package com.gas.gm.pdu.processor;

import com.gas.gm.model.Message;
import com.gas.gm.pdu.handler.MessageRequestHandler;
import com.gas.gm.pdu.handler.RequestHandler;
import com.gas.gm.pdu.session.GasGmSession;
import com.logica.smpp.Data;
import com.logica.smpp.pdu.Request;
import com.logica.smpp.pdu.Response;
import com.logica.smpp.pdu.SubmitSM;
import com.logica.smpp.pdu.SubmitSMResp;

public class MessageRequestProcessor extends GasRequestProcessor {
	
	private RequestHandler handler;

	public MessageRequestProcessor(GasGmSession session) {
		super(session);
		this.handler=new MessageRequestHandler();
	}

	@Override
	public void processRequest(Request request) throws Exception {
		Response response;
		int commandStatus;
		int commandId = request.getCommandId();
		if(commandId==Data.SUBMIT_SM){
			SubmitSMResp smresp=(SubmitSMResp)request.getResponse();
			commandStatus=handler.validateMessage((SubmitSM) request);
			if(commandStatus==Data.SM_STATE_INVALID){
				response=request.getResponse();
				session.sendPdu(response);
			}
			Message message=(Message) handler.getSerializableObject();
			smresp.setMessageId(message.getSystemId());
		}
	}

	@Override
	public void processResponse(Request request) {
		// TODO Auto-generated method stub
		super.processResponse(request);
	}
	
	

}
